<template>
    <div style="width: 100%">
        <el-form ref="form" :model="form" label-width="90px" :label-position="labelPosition"
                 style="margin-left: 3%;margin-right: 3%">
            <el-form-item label="标题 ：">
                <span>{{title}}</span>
            </el-form-item>
            <el-form-item label="日期 ：">
                <span>{{time}}</span>
            </el-form-item>
            <el-form-item label="公告类型 ：">
                <span>{{typeString}}</span>
            </el-form-item>
            <el-form-item label="公告正文 ：">
                <el-button type="text" @click="toContent">点击查看</el-button>
            </el-form-item>
            <el-form-item label="相关链接 ：">
                <span>{{linkInfo}}</span>
            </el-form-item>
            <el-form-item label="附件 ："><!-- v-if="enclosureList.length !==0"-->
                <el-table :data="enclosureList"
                          @cell-click="downloadFile"
                          border
                          style="width: 100%">
                    <el-table-column
                            prop="name"
                            label="标题">
                    </el-table-column>
                    <el-table-column
                            prop="data"
                            label="日期"
                            width="100px">
                    </el-table-column>
                </el-table>
            </el-form-item>
            <el-form-item label="下载地址 ：">
                <span style="word-wrap: break-word;">{{compressFileUrl}}</span>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import util from 'assets/js/util.js'
    import conf from 'assets/js/conf.js'

    export default {
        data() {
            return {
                enclosureList: [],
                labelPosition: 'left',
                title: '',
                time: '',
                content: '',
                form: {},
                linkInfo: '',
                typeString: '',
                fileUrl: '',
                fileId: '',
                compressFileUrl: '',
            }
        },
        mounted() {

            const _self = this;
            util.ajax({
                url: `/notice/info`,
                params: {id: util.getUrlParam(document.location.href, 'id')},
                success: function (data) {
                    _self.title = data.data.title;
                    _self.linkInfo = data.data.linkInfo || '';
                    _self.id = data.data.id;
                    _self.content = data.data.content;
                    _self.typeString = data.data.typeString;
                    _self.time = util.formatDate(data.data.sureTime) || '';
                    //_self.fileUrl = conf.baseUrl + '/file/get/' + _self.fileId + '?type=1';
                    _self.fileId = data.data.fileId;
                    _self.compressFileUrl = data.data.compressFileUrl;
                    _self.enclosureIds = data.data.enclosureIds;

                    /*if (data.enclosureList !== '') {*/
                    util.ajax({
                        url: '/file/getFileList',
                        params: {eids: _self.enclosureIds},
                        success: function (data) {
                            data.data.forEach(_file => _self.enclosureList.push({
                                id: _file.id,
                                name: _file.name,
                                url: _file.url,
                            }))
                        },
                    });

                },
            });

        },

        methods: {
            downloadFile: function (row, column, cell, event) {
                window.open(conf.baseUrl + '/file/get/' + row.id + '?type=1')
                /*+ this.caseId + '/'*/
            },
            toContent: function () {
                window.open(conf.baseUrl + '/file/get/' +this.fileId + '?type=1');
            },
        },
    }
</script>

<style scoped>
    .el-form-item__label {
        line-height: 0
    }

    span {
        word-break: normal;
        width: auto;
        display: block;
        white-space: pre-wrap;
        word-wrap: break-word;
        overflow: hidden;
    }
</style>
